package com.sdtele.tta.operation;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.sdtele.tta.dac.Dac;
import com.sdtele.tta.models.JsonRequest;
import com.sdtele.tta.models.JsonResponse;
import com.sdtele.tta.models.Team;
import com.sdtele.tta.models.User;
import com.sdtele.tta.utils.TeamUtils;

public class OperationGetSubUsers extends Operation {

	public JsonResponse handle(JsonRequest jsonRequest) {
		JsonResponse jres = new JsonResponse();
		User curUser = (User) request.getSession().getAttribute("user");		
		if (curUser != null) {
			long userId =jsonRequest.getJsonObject().get("userId").getAsLong();
			Team team = Dac.getInstance().getTeam(Dac.getInstance().getUser(userId).getTeamId());		
			List<Map<String, Object>> subUsers = new ArrayList<Map<String, Object>>();
			TeamUtils.getSubUsers(team, subUsers);			
			jres.setStatus(0);
			jres.setEntity(subUsers);
		} else {
			jres.setStatus(1);
			jres.setMessage("用户未登录");
		}
		return jres;
	}
}
